package nccloud.web.pu.storereq.action;
import nccloud.framework.web.ui.model.row.Row;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

import nccloud.framework.web.ui.model.row.Cell;
import nc.bs.dao.BaseDAO;
import nc.bs.dao.DAOException;
import nc.jdbc.framework.processor.ColumnListProcessor;
import nc.vo.pu.m422x.entity.StoreReqAppVO;
import nc.vo.pub.BusinessException;
import nccloud.framework.web.ui.pattern.billcard.BillCard;
import nccloud.web.pu.storereq.util.StoreReqScaleUtil;
import nccloud.web.scmpub.pub.event.AbstractBodyAfterAction;
import nccloud.web.scmpub.pub.utils.batchcode.SCMBatchCodeConvertor;

public class StorereqBodyAfterEditAction extends AbstractBodyAfterAction<StoreReqAppVO> {
	protected String getClassName() {
		return "nccloud.pubimpl.pu.storereq.service.StoreReqBodyAfterChangEventServiceImpl";
	}

	protected BillCard doAfterForBillCard(BillCard billCard, Map userObject) {
		(new StoreReqScaleUtil()).processBillCard(billCard);
		Row[] rows =billCard.getBody().getModel().getRows();
		for(Row row:rows) {
		
		   String mark	=(String) row.getCell("pk_material").getValue();
		   String sql="SELECT pob.norigtaxprice FROM po_order_b  pob LEFT JOIN po_order po" + 
					" ON pob.pk_order = po.pk_order WHERE  pob.pk_material= '"+mark+"'    ORDER  BY  pob.dbilldate desc ";				
	        List<BigDecimal> messages;
	        
			try {
				messages = (List<BigDecimal>) new BaseDAO().executeQuery(sql, new ColumnListProcessor());
			
	        Cell cell =new Cell();
		
			cell.setScale(-1);
		
			
			if(row.getCell("vbdef2").getValue()!=null) {
								
				continue;		   
				
			}

	        if(row.getCell("vbdef2").getValue()==null) {
	        	  if(!messages.isEmpty()) {				
	  				cell.setDisplay(messages.get(0).toString());
	  				cell.setValue(messages.get(0).toString());
	  				row.addCell("vbdef2",cell);
	  			}	
	        }
	      
			
			
			
		
			} catch (BusinessException e) {
				   e.printStackTrace();
				}  		
		}
	
		
		return billCard;
	}

	protected Map<String, Object> doBeforeForUserObject(Map<String, Object> userObject) {
		SCMBatchCodeConvertor convertor = new SCMBatchCodeConvertor();
		convertor.convertBatchCodeParam(userObject);
		return userObject;
	}
}